﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using Core.Dao;
using System.Data;

namespace Core.Business
{
    public class ServiceTypeBus
    {
        private ServiceTypeDao dao;
        public ServiceTypeBus() {
            dao = new ServiceTypeDao();
        }

        public bool insert(ServiceType serviceType) {
            return dao.insert(serviceType);
        }

        public bool update(ServiceType serviceType) {
            return dao.update(serviceType);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public ServiceType get(int id) {
            DataTable dt = dao.get(id);
            ServiceType serviceType = new ServiceType();

            if (dt.Rows.Count > 0)
            {
                serviceType.Id = Convert.ToInt32(dt.Rows[0]["SVT_ID"]);
                serviceType.Name = dt.Rows[0]["SVT_NAME"].ToString();
                serviceType.Desc = dt.Rows[0]["SVT_DESC"].ToString();
            }
            return serviceType;
        }

        public List<ServiceType> getAll(bool withDesc) {
            DataTable dt = dao.getAll();
            List<ServiceType> list = new List<ServiceType>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ServiceType serviceType = new ServiceType();
                    serviceType.Id = Convert.ToInt32(dr["SVT_ID"]);
                    serviceType.Name = dr["SVT_NAME"].ToString();
                    if(withDesc)
                    {
                        serviceType.Name += " (" + dr["SVT_DESC"].ToString() + ")";
                    }
                    serviceType.Desc = dr["SVT_DESC"].ToString();

                    list.Add(serviceType);
                }

            }
            return list;
        }
    }
}
